<?php
session_start();
date_default_timezone_set('PRC');
define('DEBUG', true);  // 开启错误报告
define("ROOT_PATH", $_SERVER['DOCUMENT_ROOT']);
define('DS', !defined('DS') ? DIRECTORY_SEPARATOR : DS);
chdir(ROOT_PATH);

if (DEBUG) {
    error_reporting(E_ALL ^ E_NOTICE ^ E_STRICT);
} else {
    error_reporting(0);
}
set_include_path(implode(PATH_SEPARATOR, array(
            realpath(ROOT_PATH . '/class'),
            realpath(ROOT_PATH . '/module'),
            get_include_path(),
        )));
//require_once ROOT_PATH . '/includes/fun_global.php';
require_once ROOT_PATH . '/class/db.class.php';
//require_once ROOT_PATH . '/includes/pagecode.php';
require_once ROOT_PATH . "/libs/SmartyBC.class.php";

// 初始化MYSQL
$db = new DB();

// 初始化SMARTY
$smarty = new SmartyBC();
$smarty->template_dir = ROOT_PATH . "/templates/admin/";
$smarty->compile_dir = ROOT_PATH . '/templates_c/';
$smarty->cache_dir = ROOT_PATH . '/cache/';
$smarty->left_delimiter = '{{';
$smarty->right_delimiter = '}}';

// 自动加载数据模型
//spl_autoload_register('autoloadModule');
function autoloadModule($className) {
    $path = ROOT_PATH . "/module/" . $className . ".php";
    if (file_exists($path)) {
        require_once $path;
    }
}

// 检测登录状态
if ($_SERVER['SCRIPT_NAME'] != '/admin/login.php') {
    header('Location: /admin/login.php');
}
?>
